package com.badlogic.androidgames.jumper;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class HighscoreTable {
	// Database table

	public static final String TABLE_NAME = "highscore";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_NAME = "name";
	public static final String COLUMN_SCORE = "score";
	public static final String COLUMN_SECONDS = "seconds";
	public static final String COLUMN_date = "date";

	private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME //
			+ "(" //
			+ COLUMN_ID + " integer PRIMARY KEY autoincrement, "//
			+ COLUMN_NAME + " TEXT NOT NULL, " //
			+ COLUMN_SCORE + " INT NOT NULL, " //
			+ COLUMN_SECONDS + " INT NOT NULL, " //
			+ COLUMN_date + " TEXT NOT NULL" //
			+ ");";

	public static void onCreate(SQLiteDatabase database){
		database.execSQL(DATABASE_CREATE);
	}
	
	public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
		Log.w(HighscoreTable.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
		database.execSQL("DROP TABLES IF EXISTS " + TABLE_NAME);
		onCreate(database);
	}
	
	
//	public void open() throws SQLException {
//		database = dbHelper.getWritableDatabase();
//	}
//
//	public void close() {
//		dbHelper.close();
//	}
//
//	public HighScore createHighscore(HighScore hs) {
//		ContentValues values = new ContentValues();
//		// values.put(HighscoreDbHelper.Columns[0], 0); //ID should auto
//		// increment
//		values.put(HighscoreDbHelper.Columns[1], hs.getName());
//		values.put(HighscoreDbHelper.Columns[2], hs.getScore());
//		values.put(HighscoreDbHelper.Columns[3], hs.getSeconds());
//		values.put(HighscoreDbHelper.Columns[4], hs.getDate());
//
//		long insertId = database.insert(HighscoreDbHelper.HIGHSCORE_TABLE_NAME, null, values);
//		Cursor cursor = database.query(HighscoreDbHelper.HIGHSCORE_TABLE_NAME, allColumns, HighscoreDbHelper.Columns[0] + " = " + insertId, null, null, null, null);
//		cursor.moveToFirst();
//		HighScore newComment = cursorToHighScore(cursor);
//		cursor.close();
//		return newComment;
//	}
//
//	public void deleteHighscore(long id) {
//		// long id = hs.getId();
//		System.out.println("Highscore deleted with id: " + id);
//		database.delete(HighscoreDbHelper.HIGHSCORE_TABLE_NAME, HighscoreDbHelper.Columns[0] + " = " + id, null);
//	}
//
//	public List<HighScore> getAllHighscores() {
//		List<HighScore> HighScores = new ArrayList<HighScore>();
//
//		Cursor cursor = database.query(HighscoreDbHelper.HIGHSCORE_TABLE_NAME, allColumns, null, null, null, null, null);
//
//		cursor.moveToFirst();
//		while (!cursor.isAfterLast()) {
//			HighScore hs = cursorToHighScore(cursor);
//			HighScores.add(hs);
//			cursor.moveToNext();
//		}
//
//		// Make sure to close the cursor
//		cursor.close();
//		return HighScores;
//	}
//
//	private HighScore cursorToHighScore(Cursor cursor) {
//		String name = cursor.getString(0);
//		int score = cursor.getInt(1);
//		int sec = cursor.getInt(2);
//		String data = cursor.getString(3);
//
//		return new HighScore(name, score, sec, data);
//	}
}